﻿// =================================================================== 
// 项目说明
// ===================================================================
// 文件： AjaxLoad
// 项目名称：AutoSite V2.0
// 类 名 称：AjaxLoad
// 创建时间：2010/07/12
// 负 责 人：郭旭阳
// 描    述：可视化设计异步加载菜单数据以及菜单管理JS
// ===================================================================
(function ($) {
    $.extend($.fn, {
        AjaxManage: {
            //定义全局变量
            publicVar: {
                $language: 0,
                $DelAllID: 0,
                $DelType: 0,
                $State: 0,
                $TypeID: 0,
                $SaveCheck: true
            },
            //删除验证txtname
            UpFileImage: function (Imgno, ty, obj) {
                var $img01 = $("#" + obj);
                _M.Include(siteBaseUrl+"/Manage/UpFile/UploadOnlineCutImg.aspx?Imgno=" + Imgno + "&ty=" + ty + "&na=" + $img01.attr("srcbak") + "&crl=" + obj + "&t=2", '', 850, 480);
            },
            //删除验证
            UpFileOneImage: function (Imgno, ty, obj) {
                var $img01 = $("#" + obj);

                _M.Include(siteBaseUrl + "/Manage/UpFile/UploadImg.aspx?Imgno=" + Imgno + "&ty=" + ty + "&name=" + $img01.attr("txtname") + "&url=" + $img01.attr("txturl") + "&na=" + $img01.attr("srcbak") + "&crl=" + obj + "&t=2", '', 500, 190);
            },
            //删除验证
            setPhotoParam: function (Imgno, ty, obj) {
                var $img01 = $("#" + obj);
                _M.Include(siteBaseUrl + "/Manage/WebSet/setphotoparam.aspx?Imgno=" + Imgno + "&ty=" + ty + "&name=" + $img01.attr("txtname") + "&url=" + $img01.attr("txturl") + "&na=" + $img01.attr("srcbak") + "&crl=" + obj + "&t=2", '', 400, 200);
            },
            //删除验证
            UpFileImage: function (Imgno, ty, obj) {
                var $img01 = $("#" + obj);
                _M.Include(siteBaseUrl + "/Manage/UpFile/UploadOnlineCutImg.aspx?Imgno=" + Imgno + "&ty=" + ty + "&na=" + $img01.attr("srcbak") + "&crl=" + obj + "&t=2", '', 850, 680);
            },
            //删除验证
            UpFileFlashImage: function ($ID) {
                _M.Include(siteBaseUrl + "/FlashImages/FlashImages.aspx?id=" + $ID, '商品图库', 570, 445);
            },
            //菜单管理
            SetMenuEdit: function ($obj) {
                _M.Include(siteBaseUrl + '/Manage/Menu/MenuEdit.aspx?ID=' + $obj, '菜单设置', 650, 430);
            },
            //删除验证
            DeleteOne: function ($delID,$obj) {              
                if ($delID != "") {
                    $().AjaxManage.DeleteCheck($delID, $obj);
                } else {
                    _M.Alert('请选择要删除的数据！');
                }
            },
            //删除验证
            DeleteAll: function ($obj) {
                var $delID = "";
                $("#tbodylist").find("input[type='checkbox']").each(function () {
                    var $this = $(this);
                    if ($this.attr("checked") == true) {
                        if ($delID == "") {
                            $delID = $this.val();
                        } else {
                            $delID += "|" + $this.val();
                        }
                    }
                });
                if ($delID != "") {
                    $().AjaxManage.DeleteCheck($delID, $obj);
                } else {
                    _M.Alert('请选择要删除的数据！');
                }
            },
            //删除验证
            DeleteAllImg: function ($obj) {
                var $delID = "";
                $("#productimg").find(".current").each(function () {
                    var $this = $(this);
                    if ($delID == "") {
                        $delID = $this.find("img").attr("id");
                    } else {
                        $delID += "|" + $this.find("img").attr("id");
                    }
                });
                if ($delID != "") {
                    $().AjaxManage.DeleteCheck($delID, $obj);
                } else {
                    _M.Alert('请选择要删除的数据！');
                }
            },
            //获取城市职级
            GetLocation: function ($pid, $obj, $selectID) {
                var $url = siteBaseUrl + "/Manage/Ajax/AjaxLocation.aspx";
                var $data = "&pid=" + $pid;
                $.ajax({
                    type: "POST",
                    url: $url,
                    timeout: 20000,
                    data: $data,
                    beforeSend: function (XMLHttpRequest) {
                    },
                    success: function (data, textStatus) {
                        $obj.html(data);
                        $obj.parents("dl").css("display", "block");
                        if ($selectID != null) {
                            $obj.find("option[value='" + $selectID + "']").attr("selected", "true");
                        }
                    },
                    complete: function (XMLHttpRequest, textStatus) {
                        //HideLoading();
                    },
                    error: function () {
                        //请求出错处理
                    }
                });
            },
            //根据地址和参数获取数据
            GetCarInfo: function ($pid, $obj, $selectID,$type) {
                var $url = siteBaseUrl + "/Manage/Ajax/AjaxCar.aspx";
                var $data = "&pid=" + $pid + "&ty=" + $type;
                $.ajax({
                    type: "POST",
                    url: $url,
                    timeout: 20000,
                    data: $data,
                    beforeSend: function (XMLHttpRequest) {
                    },
                    success: function (data, textStatus) {
                        $obj.html(data);
                        if ($selectID != null) {
                            $obj.find("option[value='" + $selectID + "']").attr("selected", "true");
                        }
                    },
                    complete: function (XMLHttpRequest, textStatus) {
                        //HideLoading();
                    },
                    error: function () {
                        //请求出错处理
                    }
                });
            },
            //删除验证
            DeleteCheck: function ($obj, $DelType) {
                $().AjaxManage.publicVar.$DelAllID = $obj;
                $().AjaxManage.publicVar.$DelType = $DelType;
                _M.ConfirmDels('您确认要删除当前数据吗？ ', -1, '$().AjaxManage.Delete();');
            },
            //删除验证
            Delete: function () {
                var $url = siteBaseUrl + "/Manage/Ajax/AjaxDelCom.aspx";
                var $data = "ty=" + $().AjaxManage.publicVar.$DelType + "&idall=" + $().AjaxManage.publicVar.$DelAllID;
                $().AjaxManage.publicVar.$DelAllID = null;
                $().AjaxManage.publicVar.$DelType = null;
                $.ajax({
                    type: "POST",
                    url: $url,
                    timeout: 20000,
                    data: $data,
                    beforeSend: function (XMLHttpRequest) {
                        //数据处理中
                        $().AjaxManage.MessageOpen("数据删除中...");
                    },
                    success: function (data, textStatus) {
                        //请求成功
                        $().AjaxManage.MessageOpen("数据删除成功...");
                        setTimeout("top.window.location.href = top.window.location.href", 500);
                    },
                    complete: function (XMLHttpRequest, textStatus) {
                        //HideLoading();
                    },
                    error: function () {
                        //请求出错处理
                    }
                });
            },
            //处理状态
            SetState: function ($DelType, $State) {
                var $delID = "";
                $("#tbodylist").find("input[type='checkbox']").each(function () {
                    var $this = $(this);
                    if ($this.attr("checked") == true) {
                        if ($delID == "") {
                            $delID = $this.val();
                        } else {
                            $delID += "|" + $this.val();
                        }
                    }
                });

                if ($delID != "") {
                    $().AjaxManage.StateCheck($delID, $DelType, $State);
                } else {
                    _M.Alert('请选择要处理的数据项！');
                }
            },
            //删除验证
            StateCheck: function ($obj, $DelType, $State) {
                $().AjaxManage.publicVar.$DelAllID = $obj;
                $().AjaxManage.publicVar.$DelType = $DelType;
                $().AjaxManage.publicVar.$State = $State;
                if ($State == 1) {
                    _M.ConfirmDels('您确认要启动当前数据项吗？ ', -1, '$().AjaxManage.State();');
                } else if ($State == 0) {
                    _M.ConfirmDels('您确认要停用当前数据项吗？ ', -1, '$().AjaxManage.State();');
                }
            },
            //删除验证
            State: function () {
                var $url = siteBaseUrl + "/Manage/Ajax/AjaxState.aspx";
                var $data = "ty=" + $().AjaxManage.publicVar.$DelType + "&idall=" + $().AjaxManage.publicVar.$DelAllID + "&state=" + $().AjaxManage.publicVar.$State;
                $().AjaxManage.publicVar.$DelAllID = null;
                $().AjaxManage.publicVar.$DelType = null;
                $.ajax({
                    type: "POST",
                    url: $url,
                    timeout: 20000,
                    data: $data,
                    beforeSend: function (XMLHttpRequest) {
                        //数据处理中
                        $().AjaxManage.MessageOpen("数据处理中...");
                    },
                    success: function (data, textStatus) {
                        //请求成功
                        $().AjaxManage.MessageOpen("数据处理成功...");
                        setTimeout("top.window.location.href = top.window.location.href", 500);
                    },
                    complete: function (XMLHttpRequest, textStatus) {
                        //HideLoading();
                    },
                    error: function () {
                        //请求出错处理
                    }
                });
            },
            //关闭提示信息
            MessageClose: function () {
                _M.CloseIframe();
                $("#TLoading").remove();
            },
            //打开提示信息
            MessageOpen: function ($Message) {
                _M.Load(null, null, $Message);
                _M.mask();
                $("#TLoading").css("z-index", 15000);
            },
            ErrorMessage: function (ID, Msg) {
                _M.MsgNo('errorMsg_' + ID);
                _M.ErrMsg(ID, Msg);
            },
            //弹层页面内操作后锁屏
            IncludeMask: function ()
            {
                $("#M_Include").css("z-index", "10007");
            },
            //SelectAllCheckBox: function ($obj) {
            //    $("#tbodylist").find("input[type='checkbox']").attr("checked", $($obj).attr("checked"));
            //},
            SelectAllCheckBox: function ($obj) {
                $("#tbodylist").find("input[type='checkbox']").each(function () {
                    this.checked = $obj.checked;
                });
               
            },
            replaceAll: function (Connect, s1, s2) {

                return Connect.replace(new RegExp(s1, "gm"), s2);

            },
            //根据地址和参数获取数据
            GetAjax: function (url, data, id) {
                var $ID = "#" + id;
                $.ajax({
                    type: "POST",
                    url: url,
                    timeout: 20000,
                    data: data,
                    beforeSend: function (XMLHttpRequest) {
                        //数据处理中

                    },
                    success: function (data, textStatus) {
                        //请求成功
                        if (data == "") {

                        } else {
                            $($ID).html(data);
                        }
                    },
                    complete: function (XMLHttpRequest, textStatus) {
                        //HideLoading();
                    },
                    error: function () {
                        //请求出错处理
                    }
                });
            },
            AjaxCarParam: function ($data, $url, $rtnUrl) {
                $.ajax({
                    type: "POST",
                    url: $url,
                    timeout: 20000,
                    data: $data,
                    beforeSend: function (XMLHttpRequest) {
                        //数据处理中
                    },
                    success: function (data, textStatus) {
                        //请求成功
                        window.location.href = $rtnUrl;
                    },
                    complete: function (XMLHttpRequest, textStatus) {
                        //HideLoading();
                    },
                    error: function () {
                        //请求出错处理
                    }
                });
            }
            
        }
    })
})(jQuery);